package com.ustc.hewei.snowflakemodule.segment.config;

import com.ustc.hewei.snowflakemodule.exception.InitException;
import com.ustc.hewei.snowflakemodule.segment.SegmentWorker;
import com.ustc.hewei.snowflakemodule.segment.service.ISegmentAllocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hewei
 * @version 1.0
 * @description: SegmentWork配置类
 * @date 2022/11/22 10:58
 */

@Configuration
public class configSegmentWorkConfig {

    @Bean
    public SegmentWorker segmentWorker(@Autowired ISegmentAllocService segmentAllocService) throws InitException {
        SegmentWorker segmentWorker = new SegmentWorker(segmentAllocService);
        boolean init = segmentWorker.init();
        if (init) {
            return segmentWorker;
        } else {
            throw new InitException("SegmentWork初始化失败!");
        }
    }
}
